<?php
define("member_keyword", "hyjf");
define("member_no_search_keyword", "no");
define("member_tel_search_keyword", "tel");
define("member_czjf_keyword", "czjf");
define("member_xfjf_keyword", "xfjf");
define("member_hdjf_keyword", "hdjf");

define("verifycode_keyword", "yzm");
define("verifycode_use_keyword", "sy");

define("order_no_search_keyword", "orderno");
define("reserve_no_search_keyword", "reserveno");

/*
Module Group: employeeManage
Module Group Name: 员工管理
Description:员工管理模块可以添加员工,以及配置,查看员工操作
Version: 1.0
Iconurl: http://www.happyidea.com.cn/resource/wx_icon/default.png
Author: holiny
Modules: employeeManage
Display: 1
*/

class employeeManageModule extends Module {
	/*
	 * 在构造函数中装载所依赖的类或其他文件
	*/
	function __construct() {
		$this->includePhp('employeeManage', 'employeeManage');
	}
	/*
	 * 激活创建数据库
	*/
	public function activate() {
// 		Module::importSQL(module_sql_path('employeeManage'));
	}
	
	public function run($message, $material, $userStatus) {	
		//$VerifyCode = M("module_verify_code");
// 		$CustomerUser = new Model();
		
		
		$cid = 	Session::$user['customerId'];
		$materialId= $material->id;
		
		$materialObj = simplexml_load_string($material->xml,
				'SimpleXMLElement', LIBXML_NOCDATA);
		// 获取素材欢迎语中的欢迎语和感谢语
		$materialWelcome = $materialObj->welcome; 
		
		$materialExit = $materialObj->exit; 
		$materialInputUserName = $materialObj->inputusername; 
		$materialErrorInputUserName = $materialObj->errorinputusername; 
		$materialInputPassword = $materialObj->inputpassword; 
		$materialErrorInputPassword = $materialObj->errorinputpassword; 
		$materialErrorUserNotFound = $materialObj->errorusernotfound; 
		
		$materialInputVerifyCode = $materialObj->inputverifycode; 
		$materialErrorInputVerifyCode = $materialObj->errorinputverifycode; 
		$materialErrorVerifyCodeNotFound = $materialObj->errorverifycodenotfound; 
		$materialErrorVerifyCodeIsClaim = $materialObj->errorverifycodeisclaim; 
		$materialVerifyCodeIsClaim = $materialObj->verifycodeisclaim; 
		$materialVerifyCodeInfo = $materialObj->verifycodeinfo; 
		
		$materialMemberInfo = $materialObj->memberinfo; 
		$materialInputMember = $materialObj->inputmember; 
		$materialErrorInputMember = $materialObj->errorinputmember; 
		$materialMemberNotFound = $materialObj->errormembernotfound; 
		$materialMemberScoreOk = $materialObj->memberscoreok; 
		
		$materialKeywordError = $materialObj->keyworderror; 
		
		$materialFail = $materialObj->fail; 
		$materialError = $materialObj->error; 
		
		
		// 所有回复均为文本
		$rm = $message->reply(message_type_text);
		
		// 任何时候只要输入q，就退出结束流程
		if (strcasecmp( trim($message->content), "q") == 0 ) {
			
			R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'退出',$message->content));
			
			$userStatus->reserve1 = '';
			$userStatus->reserve2 = '';
			$userStatus->reserve3 = '';
			$userStatus->reserve4 = '';
			$userStatus->reserve5 = '';
			$userStatus->status = '0';
			UserStatus::end($userStatus);
			$rm->content = $materialExit;
			return $rm;
		}
				
		// 用户刚进入的时候状态为空字符串，并更改状态为1
		if (!isset($userStatus)) {
			$us = UserStatus::create($message->fromUserName, $material->id);
			$us->status = '1';
			UserStatus::begin($us);
			$rm->content = $materialInputUserName;
			//$rm->funcFlag = 1;//加星标
			return $rm;
		} else if($userStatus->reserve1 != ''){
			//用户登录成功 检索每次输入是否是关键词
			if (strcasecmp(trim($message->content), member_keyword) == 0  ||
			strcasecmp(trim($message->content), verifycode_keyword) == 0) {
// 				$userStatus->reserve2 = member_keyword;
				$userStatus->reserve3 = '';
				$userStatus->reserve4 = '';
				$userStatus->status = '3';
				UserStatus::update($userStatus);
					
			}
		}
		
		
		
		switch ($userStatus->status) {
			case '1':
				//判断是否是text，如果不是提示错误，是记录用户姓名，提示输入手机号
				if($message->msgType!=message_type_text) {
					$rm->content = $materialErrorInputUserName;
					break;
				}
				// 切换客户
				Session::switchCustomer(0);
				//Session::switchCustomer($cid);
				$CustomerUser = M("customer_user");
				$conditionName['email'] = array('eq',trim($message->content));
				$conditionName['customerId'] = array('eq',$cid);
				$conditionName['agent'] = array('eq','service');
				$resultUser = $CustomerUser->where($conditionName)->select();
				Session::switchCustomer($cid);
				
				if(!$resultUser){
					$rm->content = $materialErrorInputUserName;
					break;
				}
				
// 				// 判断是否是wx1-wx25,不是则返回错误
// 				$arr = explode("wx",$message->content);
// 				if (!((count($arr)==2)&&((int)$arr[1]>0)&&((int)$arr[1]<26)))
// 				{
// 					$rm->content = $materialErrorInputUserName;
// 					break;
// 				}
				// 存入登录名,将登录名存入预留字段中
				$userStatus->reserve1 = $message->content;
				// 存入状态
				$userStatus->status = '2';
				UserStatus::update($userStatus);
				$rm->content = $materialInputPassword;
				break;
			case '2':
				//判断是否是text，如果不是提示错误
				if($message->msgType!=message_type_text) {
					$rm->content = $materialErrorInputPassword;
					break;
				}
				
				// 切换客户
				Session::switchCustomer(0);
				//Session::switchCustomer($cid);
				$CustomerUser = M("customer_user");
				$conditionPsw['email'] = array('eq', trim($userStatus->reserve1));
				$conditionPsw['password'] = array('eq', Encryption::password(trim($message->content)));
				$conditionPsw['customerId'] = array('eq',$cid);
				$conditionName['agent'] = array('eq','service');
				$resultUser = $CustomerUser->where($conditionPsw)->find();
				Session::switchCustomer($cid);
				if(!$resultUser){
					$rm->content = $materialErrorInputPassword;
					break;
				}
				
				// 存入状态,提示输入关键词,以及员工id
				$userStatus->reserve5 = $resultUser['fullName'];
				$userStatus->reserve1 = $resultUser['id'];
				$userStatus->status = '3';
				UserStatus::update($userStatus);
				$rm->content = $materialWelcome;			
				
				R('EmployeeManage/addUserActionDetail',
				array($cid,$userStatus->reserve1,'登录','登录终端查询系统',$resultUser['fullName']));
				
				break;
			case '3':
				//判断是否是text，如果不是提示错误
				if($message->msgType!=message_type_text) {
					$rm->content = $materialError;
					break;
				}
				
				if (strcasecmp(trim($message->content), member_keyword) == 0 ) {
					$userStatus->status = '4';
					$userStatus->reserve2 = member_keyword;
					UserStatus::update($userStatus);
					$rm->content = $materialInputMember;
					
					R('EmployeeManage/addUserActionDetail',
					array($cid,$userStatus->reserve1,member_keyword,'会员',member_keyword));
					
					break;
					
				}else if(strcasecmp(trim($message->content), verifycode_keyword) == 0 ){
					$userStatus->status = '4';
					$userStatus->reserve2 = verifycode_keyword;
					UserStatus::update($userStatus);
					$rm->content = $materialInputVerifyCode;
					
					R('EmployeeManage/addUserActionDetail',
					array($cid,$userStatus->reserve1,verifycode_keyword,'验证码',verifycode_keyword));
					
					break;
				}else{
					///
					$rm->content = $materialKeywordError;
					R('EmployeeManage/addUserActionDetail',
					array($cid,$userStatus->reserve1,$message->content,'误操作',$message->content));
					
					break;
				}
					
			case '4':
				//判断是否是text，如果不是提示错误
				if($message->msgType!=message_type_text) {
					$rm->content = $materialError;
					break;
				}
				
				if (strcasecmp(trim($userStatus->reserve2), member_keyword) == 0 ) {
					//查询会员
// 					$arr = explode("wx",$message->content);
// 					if (!((count($arr)==2)&&((int)$arr[1]>0)&&((int)$arr[1]<26)))
// 						{
// 							$rm->content = $materialErrorInputMember;
// 							break;
// 					}
					$memberInfo = strtolower(trim($message->content));
					
					if(stripos($memberInfo,member_tel_search_keyword) !== false){
						
						$arr = explode(member_tel_search_keyword,$memberInfo);
						
						if (count($arr) != 2){
							
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_tel_search_keyword,'误操作',$message->content));
								
							$rm->content = $materialErrorInputMember;
							break;
						}else{
							
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_tel_search_keyword,'会员手机号查询',$message->content));
							
							
							Session::switchCustomer(0);
							$member = R('Member/getMemberByPhone',array($arr[1],$cid));
							Session::switchCustomer($cid);
							
							if($member == 0){
								$userStatus->reserve3 = '';
								$userStatus->reserve4 = '';
								UserStatus::update($userStatus);
								$rm->content = $materialMemberNotFound;
								break;
							}else{
								//返回会员信息
								$userStatus->reserve3 = $member['id'];
								$userStatus->reserve4 = $member['fromUserName'];
								UserStatus::update($userStatus);
								
								if($member['interactScore'] == null){
									$member['interactScore']=0;
								}
								if($member['consumeScore'] == null){
									$member['consumeScore'] = 0;
								}
								if($member['storedValue'] == null){
									$member['storedValue'] = 0.00;
								}
								$xml = str_replace(
										array('{search}','{member}','{interact}','{consume}','{storedValue}'),
										array('手机号码',$arr[1],$member['interactScore'],$member['consumeScore'],$member['storedValue']),
										$materialMemberInfo);
								
								$rm->content = $xml;
								
							}
						}
						
						
					}else if(strpos(strtolower(trim($message->content)),member_no_search_keyword) !== false){
						
						$arr = explode(member_no_search_keyword,$memberInfo);
						
						if (count($arr) != 2){
							

							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_no_search_keyword,'误操作',$message->content));
								
								
							$rm->content = $materialErrorInputMember;
							break;
						}else{
							

							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_no_search_keyword,'会员编号查询',$message->content));
							
							Session::switchCustomer(0);
							$member = R('Member/getMemberByNumber',array($arr[1],$cid));
							Session::switchCustomer($cid);
							
								
							if($member == 0){
								$userStatus->reserve3 = '';
								$userStatus->reserve4 = '';
								UserStatus::update($userStatus);
								$rm->content = $materialMemberNotFound;
								break;
							}else{
								//返回会员信息
								$userStatus->reserve3 = $member['id'];
								$userStatus->reserve4 = $member['fromUserName'];
								UserStatus::update($userStatus);
								
								if($member['interactScore'] == null){
									$member['interactScore']=0;
								}
								if($member['consumeScore'] == null){
									$member['consumeScore'] = 0;
								}
								if($member['storedValue'] == null){
									$member['storedValue'] = 0.00;
								}
								
								
								$xml = str_replace(
										array('{search}','{member}','{interact}','{consume}','{storedValue}'),
										array('会员编号',$arr[1],$member['interactScore'],$member['consumeScore'],$member['storedValue']),
										$materialMemberInfo);
						
								$rm->content = $xml;
							}
						}
						
						
					}else if(strpos(strtolower(trim($message->content)),member_czjf_keyword) !== false){
						//直接对查询的会员做储值操作
						
						$arr = explode(member_czjf_keyword,$memberInfo);
						
						if (count($arr) != 2){
							
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_czjf_keyword,'会员误操作',$message->content));
							
							$rm->content = $materialFail;
							break;
						}else{
							////
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_czjf_keyword,'会员储值卡操作',$message->content));
// 							R('EmployeeManage/addUserActionDetail',
// 							array($cid,$userStatus->reserve1,member_czjf_keyword,'会员储值卡操作',$message->content,$userStatus->reserve3));
								
							
							$memberId = $userStatus->reserve3;
							$fromUserName = $userStatus->reserve4;
							if($memberId == ''){
								$rm->content = $materialFail;
								break;
							}else{
								Session::switchCustomer(0);
								//会员储值操作
								$changeOk = R('Member/addMemberStoredValueDetail',
										array($cid,$fromUserName,$memberId,'stored',0,0,$arr[1],NULL,module_handle_employeeManage,'操作人员'.$userStatus->reserve5));
								Session::switchCustomer($cid);
								
								if($changeOk){
									$rm->content = $materialMemberScoreOk;
									break;
								}else{
									$rm->content = $materialFail;
									break;
								}
							}
						
						}
						
					}else if(strpos(strtolower(trim($message->content)),member_hdjf_keyword) !== false){
						//直接对查询的会员做互动积分操作
						
						$arr = explode(member_hdjf_keyword,$memberInfo);
						
						if (count($arr) != 2){
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员互动积分误操作',$message->content,$userStatus->reserve3));
								
							$rm->content = $materialFail;
							break;
						}else{
							////
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员互动积分操作',$message->content));
// 							R('EmployeeManage/addUserActionDetail',
// 							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员互动积分操作',$message->content,$userStatus->reserve3));
								
							$memberId = $userStatus->reserve3;
							$fromUserName = $userStatus->reserve4;
							if($fromUserName ==''){
								$rm->content = $materialFail;
								break;
							}else{
								//会员互动积分操作
								$changeOk = set_point_by_fromUserName($fromUserName,module_handle_employeeManage,false,'操作人员'.$userStatus->reserve5,$materialId,NULL,$arr[1]);
									
								if($changeOk){
									$rm->content = $materialMemberScoreOk;
									break;
								}else{
									$rm->content = $materialFail;
									break;
								}
							}
						}
						
						
					}else if(stripos(strtolower(trim($message->content)),member_xfjf_keyword) !== false){
						//直接对查询的会员做消费积分操作
						
						$arr = explode(member_xfjf_keyword,$memberInfo);
						
						if (count($arr) != 2){
							$rm->content = $materialFail;
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员消费积分误操作',$message->content,$userStatus->reserve3));
								
							break;
						}else{
							////
							
							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员消费积分操作',$message->content));
// 							R('EmployeeManage/addUserActionDetail',
// 							array($cid,$userStatus->reserve1,member_hdjf_keyword,'会员消费积分操作',$message->content,$userStatus->reserve3));
								
							$memberId = $userStatus->reserve3;
							$fromUserName = $userStatus->reserve4;
							if($fromUserName ==''){
								$rm->content = $materialFail;
								break;
							}else{
								Log::write('操作人员'.$userStatus->reserve5);
								//会员消费积分操作
								$changeOk = saveConsumePointInfo($fromUserName,module_handle_employeeManage,$arr[1],'操作人员'.$userStatus->reserve5,$materialId,NULL);
									
								if($changeOk){
									$rm->content = $materialMemberScoreOk;
									break;
								}else{
									$rm->content = $materialFail;
									break;
								}
							}
						}
					}
					else{
						$rm->content = $materialError;
						break;
					}
					
// 					$userStatus->status = '4';
// 					$userStatus->reserve2 = member_keyword;
// 					UserStatus::update($userStatus);
// 					$rm->content = $materialInputMember;
					break;
						
				}else if(strcasecmp(trim($userStatus->reserve2), verifycode_keyword) == 0 ){
					//查询验证码状态信息
// 					$userStatus->status = '4';
// 					$userStatus->reserve2 = verifycode_keyword;
// 					UserStatus::update($userStatus);
// 					$rm->content = $materialInputVerifyCode;
// 					break;
					
					if(stripos(trim($message->content),verifycode_use_keyword) !== false ){
						if($userStatus->reserve3 == ''){

							R('EmployeeManage/addUserActionDetail',
							array($cid,$userStatus->reserve1,verifycode_use_keyword,'领用验证码误操作',$message->content));
								
							//输入验证码提示
							$rm->content = $materialErrorInputVerifyCode;
							break;
						}else{
							
							// 领用
							$resultCode = employeeManage::claim($userStatus->reserve3, $userStatus->reserve1);
							// 				$result = R('VerifyCode/claim',array($message->content,$loginName));
							// 存在该验证码，但是已经被领用，提示已经被领用
							if($resultCode == code_verifycode_notexist) {
								R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'领用验证码',$userStatus->reserve3.$materialErrorVerifyCodeNotFound));
								
								$rm->content = $materialErrorVerifyCodeNotFound;
								break;
							} else if($resultCode == code_verifycode_claimed) {
								R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'领用验证码',$userStatus->reserve3.$materialErrorVerifyCodeIsClaim));
								
								$rm->content = $materialErrorVerifyCodeIsClaim;
								break;
							}else if($resultCode == code_red_envelope_verify_code_has_expire){
								R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'领用验证码',$userStatus->reserve3.'已过期'));
								
								$rm->content = '此验证码已经过期';
								break;
							}
							
							$VerifyCode = M("module_verify_code");
							$reward = $VerifyCode->where("code='$userStatus->reserve3'")->getField('reward');
							R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'领用验证码',$userStatus->reserve3.'成功领用'.$reward));
							
							$xml = str_replace(array('{code}','{reward}'),
									 	array($userStatus->reserve3,$reward), 
										$materialVerifyCodeIsClaim);
							// 存在该验证码，领用，提示成功
							$rm->content = $xml;
							
							$userStatus->reserve3 = '';
							UserStatus::update($userStatus);
// 							R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'领用验证码',$xml));
							break;
						}
						
					}else{
					////保存当前验证码
						R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'验证码',$message->content));
						
						// 调用action，先检查该验证码是否存在
						$verifyCodeInfo = employeeManage::verify($message->content);
						// 				$result = R('VerifyCode/verify',array($message->content));
						// 不存在该验证码，提示该验证码不存在
						if($verifyCodeInfo == code_verifycode_notexist) {
							
							$userStatus->reserve3 = '';
							UserStatus::update($userStatus);
							$rm->content = $materialErrorVerifyCodeNotFound;
							break;
						} else if($verifyCodeInfo['isClaim'] == 1) {
							
							$userStatus->reserve3 = trim($message->content);
							UserStatus::update($userStatus);
							$xml = str_replace(
										array('{code}','{isClaim}','{reward}'),
										array($verifyCodeInfo['code'],'已经使用',$verifyCodeInfo['reward']),
										$materialVerifyCodeInfo);
							$rm->content = $xml;
							break;
						}else if($verifyCodeInfo['isClaim'] == 0){

							$userStatus->reserve3 = trim($message->content);
							UserStatus::update($userStatus);
							$xml = str_replace(
									array('{code}','{isClaim}','{reward}'),
									array($verifyCodeInfo['code'],'尚未使用',$verifyCodeInfo['reward']),
									$materialVerifyCodeInfo);
							$rm->content = $xml;
							break;
						}
						
					}
					
				}else{
					///
					R('EmployeeManage/addUserActionDetail',array($cid,$userStatus->reserve1,$message->content,'误操作',$message->content));
					
					$rm->content = $materialKeywordError;
					break;
				}
		}
		
		return $rm;
	}
	
	/*
	 * 调用插件资源
	*/
	public function call($user, $method, $param) {
		switch ($method) {
			case 'manageSystem':
				employeeManage::manageSystem();
				break;
            case 'index':
                $id = $param->id;
                $fromType = $param->fromType;
                employeeManage::index($id,$fromType);
                break;
            case 'binding':
                $email = $param->email;
                $password = $param->password;
                if (!isset($email) || !isset($password)) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                employeeManage::binding($email,$password);
                break;
            case 'storeOrder':
                $id=$param->id;
                if (!isset($id)) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                employeeManage::storeOrder($id);
                break;
            case "storeOrderList":
                $id=$param->id;
                if (!isset($id)) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                $status = $param->status;
                $name=$param->search;
                $start=$param->start;
                $limit=$param->limit;
                employeeManage::storeOrderList($id,$name,$status,$start,$limit);
                break;
            case 'orderDetail':
                $id = $param->id;
                if (!isset($id)) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                employeeManage::orderDetail($id);
                break;
            case 'updateOrder':
                $id = $param->id;
				$pCode = $param->pCode;
				$cUserId = $param->cUserId;
                if (!isset($id)) {
                    Output::instance()->resultCode(code_lackof_param);
                    return;
                }
                employeeManage::updateOrder($id, $pCode, $cUserId);
                break;
			case 'login':
				
				$email = $param->email;
				$password = $param->password;
				if (!isset($email) || !isset($password)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				employeeManage::login($email,$password);
				
				break;
			case 'fakelogin':
				employeeManage::fakelogin();
				break;
			case 'actionSystem':
				employeeManage::actionSystem();
				break;

			case 'searchSystem':
				$type = $param->type;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;
				
				if (!isset($type) || !isset($employeeUId)|| !isset($employeeUName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				employeeManage::searchSystem($employeeUId,$employeeUName,$type);
				break;
				
			case 'search':
				$type = $param->type;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;
				$search = $param->search;
				$customerId = Session::$user['customerId'];
				
// 				$customerId = $_GET['customerId'];
				if (!isset($type) || !isset($employeeUId)|| !isset($employeeUName) || !isset($search)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				if(strcasecmp($type, 'verifyCode') == 0){
					R('EmployeeManage/addUserAction',
					array($customerId,$employeeUId,verifycode_keyword,'验证码',$search));
					
					employeeManage::searchVerifyCode($search,$employeeUId,$employeeUName);
					
					
				}else if(strcasecmp($type, 'telMember') == 0){
				
					R('EmployeeManage/addUserAction',
					array($customerId,$employeeUId,member_tel_search_keyword,'会员手机号查询',$search));
					
					Session::switchCustomer(0);
					$member = R('Member/getMemberByPhone',array($search,$customerId));
					Session::switchCustomer($customerId);
						
					if($member){
						Output::instance()->module('employeeManage', 'member_info')->object($member);
					}else{
						Output::instance()->resultCode(code_user_not_exist);
					}

				}else if(strcasecmp($type, 'noMember') == 0){
					
					R('EmployeeManage/addUserAction',
					array($customerId,$employeeUId,member_no_search_keyword,'会员编号查询',$search));
					
					Session::switchCustomer(0);
					$member = R('Member/getMemberByNumber',array($search,$customerId));
					Session::switchCustomer($customerId);
					if($member){
						Output::instance()->module('employeeManage', 'member_info')->object($member);
					}else{
						Output::instance()->resultCode(code_user_not_exist);
					}
					
				}else if(strcasecmp($type, 'order') == 0){
					
					R('EmployeeManage/addUserAction',
					array($customerId,$employeeUId,order_no_search_keyword,'订单编号查询',$search));
						
					employeeManage::getOrderInfo($search,$customerId);
				}else if(strcasecmp($type, 'reserveOrder') == 0){
					
					R('EmployeeManage/addUserAction',
					array($customerId,$employeeUId,reserve_no_search_keyword,'预订编号查询',$search));
					
					employeeManage::getReserveOrderInfo($search,$customerId);
				}
				
				break;
				
			case 'claimVerifyCode':
				$code = $param->code;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;
				
				if (!isset($code) || !isset($employeeUId)|| !isset($employeeUName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				
				employeeManage::claim($code,$employeeUId);
					
				break;
				
			case 'updateOrderTip':
				$oid = $param->oid;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;
				$sellerNote = $param->sellerNote;
				$sellerRemark = $param->sellerRemark;
				$status = $param->status;
				
				$customerId = Session::$user['customerId'];
				if (!isset($oid) || !isset($employeeUId)|| !isset($employeeUName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}
				$action= '';
				if(!isset($sellerNote)){
					$sellerNote = NULL;
					$action = $action.'给买家说明'.$sellerNote.';';
				}
				if(!isset($sellerRemark)){
					$sellerRemark =NULL;
					$action = $action.'卖家备注'.$sellerRemark.';';
				}
				
				if(!isset($status)){
					$status = NULL;
					$action = $action.'状态'.$status.';';
				}
				
				Session::switchCustomer(0);
				//会员储值操作
				$changeOk = R('Product/updateOrderTipByOrderId',
						array($oid,$sellerNote,$sellerRemark,$status,true));
				
				Session::switchCustomer($customerId);
				
				R('EmployeeManage/addUserAction',
				array($customerId,$employeeUId,'orderchange','订单状态修改操作',$action));
				
// 				if($changeOk){
// 					Output::instance()->resultCode(code_success);
// 				}else{
// 					Output::instance()->resultCode(code_custom_error, '操作失败');
// 				}
				
				break;
			case 'getSaleSourceOrderList':
				/*$type = $param->type;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;

				if (!isset($type) || !isset($employeeUId)|| !isset($employeeUName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}*/
				/*$search=null,$status=0,$start=0,$limit=10*/
				employeeManage::getSaleSourceOrderList($param->search,$param->status,$param->start,$param->limit,$param->type);
				break;
			case 'saleSourceOrderDetail':
				/*$type = $param->type;
				$employeeUId = $param->euid;
				$employeeUName = $param->euname;

				if (!isset($type) || !isset($employeeUId)|| !isset($employeeUName)) {
					Output::instance()->resultCode(code_lackof_param);
					return;
				}*/

				employeeManage::saleSourceOrderDetail($param->oid);
				break;
			case 'getEmployeeCfg':
				employeeManage::getEmployeeCfg();
				break;
		}
	}
}

$module = new employeeManageModule();
Module::addModule($module);
?>